let delItem;
let deleteDialog = $(`
    <div class="modal fade" tabindex="-1">
    <!--更新对话框-->
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">确认删除管理员信息</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                您确定要删除这个管理员吗?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary _save">确认</button>
            </div>
        </div>
    </div>
</div>
    `);
    console.debug(deleteDialog);
    $("body").append(deleteDialog);


    let btn = deleteDialog[0].querySelector("._save");

    btn.onclick = function(){
        //验证输入参数
        let param = new URLSearchParams();
        param.append("adminId",delItem.adminId);
        console.info(param.toString());
        fetch("admin-delete.let",{
            method: 'POST', // *GET, POST, PUT, DELETE, etc.
            mode: 'cors', // no-cors, *cors, same-origin
            cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
            credentials: 'include', // include, *same-origin, omit
            headers: {
                // 'Content-Type': 'application/json'
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            redirect: 'follow', // manual, *follow, error
            referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
            // body: JSON.stringify(data) // body data type must match "Content-Type" header
            body: param
        }).then(r=>r.json()).then(data=>{
            console.debug(data);
            if(data.ok){
                deleteDialog.modal('hide');
                window.postMessage("loadData");//发送消息
            }else{
                alert(data.msg);
            }
        }).catch(e=>{
            console.error(e);
        });
    }


export default function (item) {
    delItem = item;
    deleteDialog.modal('show');
}
